<?
ob_start(); 
include("../common/header.html");
include('../common/autoload.php');
$out_html = ob_get_contents();
ob_end_clean();
include_once("../class/ProOrder.php");
set_time_limit(300);
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$soap = SoapInit::GetSoapInside();
$memberID = $_SESSION['sid'];
if ($memberID!=1) {
    exit('Access Denied!');
}
// 异步获取对应的景点门票
if($_SERVER['HTTP_REQUEST_TYPE']=='getTicket'){
	$sql='SELECT id,title FROM uu_jq_ticket WHERE landid='.($_REQUEST['landid']+0);//
	$GLOBALS['le']->query($sql);
	$tickes = array();
	while($row=$GLOBALS['le']->fetch_assoc()){
		$tickes[]=$row;
	}
	if(count($tickes)){
		echo json_encode(array('s'=>'success','content'=>$tickes));
	}else{
		echo json_encode(array('s'=>'fail'));
	}
	exit;
}

$btime=$_REQUEST['begintime']?$_REQUEST['begintime']:date("Y-m-d");
$etime=$_REQUEST['endtime']?$_REQUEST['endtime']:date("Y-m-d");
$by=$_REQUEST['by']?$_REQUEST['by']:"lid";
$option=array();
if(count($_REQUEST['status'])>0){
	$option['status']=implode("|",$_REQUEST['status']);
}

// 景点查询
if(isset($_REQUEST['landid']))	$option['lid'] = $_REQUEST['landid'];

// 门票查询
if(isset($_REQUEST['ticket'])){
	$t = explode("_",$_REQUEST['ticket']);$option['tid']=$t[0];
}
//交易时间类型
$timeType = isset($_REQUEST['time_type'])? abs($_REQUEST['time_type']) : 1;
//分销商ID
$fid = isset($_REQUEST['fid']) ? abs($_REQUEST['fid']) : 0;
$aid = isset($_REQUEST['aid']) ? abs($_REQUEST['aid']) : 0;
//TODO::直销
$option['n'] = 99999;
$obj = new AdminProOrder($memberID, $soap);

if ($_GET['testcgp']==1) {
    print_r($r);
    exit;
}

//会员数据
$aDistorsNames = include '../module/link_product/Member.cache.php';
//goto lids;
$r = $obj->_orderSum($btime." 00:00:00",$etime." 23:59:59",$by,$option, $timeType, $fid, $aid);
if($_GET['by']=='mid' || $_GET['by']=='aid'){
    foreach($r as $k => $v){
        if($_SESSION['memberID']==1 && $_SESSION['dtype']==9){
            $r[$k]['title']=$aDistorsNames[$k];
        }else{
            $r[$k]['title']=$memberNames[$k];
        }
    }
}

//区分测试和非测试景区
if(is_array($r)){
//    lids:
    $dir = '/var/www/html/new/d/module/zax/admin_report/test_lid.txt';
    $a=filemtime($dir);
    if($_SERVER['REQUEST_TIME']-$a>4000){
        $sql = "select id from pft_member where group_id=2";
        $GLOBALS['le']->query($sql);
        $row = array();
        while($row=$GLOBALS['le']->fetch_assoc()){
            $r_fid[] = $row['id'];
        }
        $rm_fid = rtrim(json_encode($r_fid),']');
        $rm_fid = ltrim($rm_fid,'[');
        $sql = "select id from uu_land where apply_did in ($rm_fid) and status=1";
        $GLOBALS['le']->query($sql);
        $row = array();
        while($row=$GLOBALS['le']->fetch_assoc()){
            $r_lid[] = (int)$row['id'];
        }
        file_put_contents($dir,json_encode($r_lid));
    }else{
        $r_lid = json_decode(file_get_contents($dir),true);
    }
//    print_r($r_lid);
//    exit;
    switch ($_GET['is_test']) {
    	case '1'://测试帐号
            case1:
    		foreach($r as $k => $v){
                if(!in_array($v['lid'],$r_lid))
                    unset($r[$k]);
            }
    		break;

    	case '2'://非测试帐号
            foreach($r as $k => $v){
                if(in_array($v['lid'],$r_lid))
                    unset($r[$k]);
            }
    		break;
        default:
            goto case1;
    }
}

$titleT=array("lid"=>"景区名称","tid"=>"票类名称","mid"=>"分销商名称");
$totals=array();
/*导出EXCEL处理程序--begin-*/

include("../ExcelHandle.php");
/*导出EXCEL处理程序--end*/
echo $out_html;
$from="sale";
// 获取产品
$products = array(); //系统中的所有在售产品

$sql = "SELECT id,title,getPy(title,1) as py FROM uu_land WHERE status=1 ORDER BY py ASC";
$GLOBALS['le']->query($sql);
while($row=$GLOBALS['le']->fetch_assoc()){
    if (!is_numeric($row['py'])) {
        $products[$row['id']] = $row['py'] . '-'. $row['title'];
    }
}
include("orderReport_today.tpl");
include("../common/footer.html");
?>